package com.zhku.shoppingspringboot.common;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 作者：zjy
 * 时间：2024/8/7 18:16
 * 描述:无bug
 */
@Data
@ApiModel("分页结果")
public class myPageInfo<T> implements Serializable {
    @ApiModelProperty(
            value = "当前页码",
            position = 1
    )
     private  int pageNum;

    @ApiModelProperty(
            value = "每页数量",
            position = 2
    )
    private  int pageSize;

    @ApiModelProperty(
            value = "总页数",
            position = 3
    )
    private int pages;
    @ApiModelProperty(
            value = "数据总数",
            position = 4

    )
    private int total;

    @ApiModelProperty(
            value = "数据",
            position = 5

    )
    private List<T> info;

    public static <T> myPageInfo<T> conversion(PageInfo<T> pageInfo){
        myPageInfo<T> p=new myPageInfo<>();
        p.pageNum=pageInfo.getPageNum();
        p.pageSize=pageInfo.getPageSize();
        p.pages=pageInfo.getPages();
        p.total=(int) pageInfo.getTotal();
        p.info=pageInfo.getList();
        return p;
    }
}
